using System;
using System.Globalization;
using System.Windows.Data;

namespace MapInfo.Toolbox.UI.Views
{
    //http://stackoverflow.com/users/87399/joe-white
    public class ViewConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //Expect:	ViewModels.BobViewModel
            //Want:		Views.BobView
            //Warning:	Highly reliant on correct *convention* !
            string viewForModel = value.GetType().ToString().Replace("Model", "");

            Type instanceType = Type.GetType(viewForModel);

            return Activator.CreateInstance(instanceType);
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return value;
            //throw new NotSupportedException();
        }
    }
}